/*  File Name	: MonitorSock.cpp
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-7-2
 *  Description:
 */

#ifndef MONITORSOCK_CPP_
#define MONITORSOCK_CPP_

#include "MonitorSock.h"
#include "Service.h"

template<class MONITOR,class SERVICE>
MonitorAcceptor<MONITOR,SERVICE>::MonitorAcceptor(MONITOR *monitor)
{
	this->monitor_ = monitor;
}

template<class MONITOR,class SERVICE>
MonitorAcceptor<MONITOR,SERVICE>::~MonitorAcceptor()
{

}

template<class MONITOR,class SERVICE>
void MonitorAcceptor<MONITOR,SERVICE>::monitor(MONITOR *monitor)
{
	this->monitor_ = monitor;
}

template<class MONITOR,class SERVICE>
int MonitorAcceptor<MONITOR,SERVICE>::make_svc_handler(SERVICE *&svc)
{
	if(NULL==this->monitor_ ||this->monitor_->svc_pool()->pop(svc)!=0)
	{
		svc = NULL;
		return -1;
	}
//	if(svc->unique_id()==0)
//	{
//		svc->set_unique_id(this->monitor_->svc_unique_id());
//	}
	svc->set_unique_id(this->monitor_->svc_unique_id());
	svc->reactor(this->monitor_->reactor());
	svc->monitor(this->monitor_);
	return 0;
}


///////////////////////////////////////////////////////////////////

template<class MONITOR,class SERVICE>
MonitorConnector<MONITOR,SERVICE>::MonitorConnector(MONITOR *monitor)
{
	this->monitor_ = monitor;
}

template<class MONITOR,class SERVICE>
MonitorConnector<MONITOR,SERVICE>::~MonitorConnector()
{

}

template<class MONITOR,class SERVICE>
void MonitorConnector<MONITOR,SERVICE>::monitor(MONITOR *monitor)
{
	this->monitor_ = monitor;
}

template<class MONITOR,class SERVICE>
int MonitorConnector<MONITOR,SERVICE>::make_svc_handler(SERVICE *&svc)
{
	if(NULL==this->monitor_ ||this->monitor_->svc_pool()->pop(svc)!=0)
	{
		svc = NULL;
		return -1;
	}
//	if(svc->unique_id()==0)
//	{
//		svc->set_unique_id(this->monitor_->svc_unique_id());
//	}
	svc->set_unique_id(this->monitor_->svc_unique_id());
	svc->reactor(this->monitor_->reactor());
	svc->monitor(this->monitor_);
	return 0;
}

#endif //MONITORSOCK_CPP_
